﻿#include "daq331m.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#if WIN32
#include <windows.h>
#define LOAD_LIBRARY_FUNC(dll, func) GetProcAddress(dll, func)
#define FREE_LIBRARY_FUNC(dll) FreeLibrary(dll)
#define LIBRARY_NAME "libdaq-2.0.0.dll"
#elif __linux__
#include <dlfcn.h>
#define LOAD_LIBRARY_FUNC(dll, func) dlsym(dll, func)
#define FREE_LIBRARY_FUNC(dll) dlclose(dll)
#define LIBRARY_NAME "liblibdaq-2.0.0.so"
#endif

static void create_device(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ != NULL)
    {
        return;
    }
    daq331m->daq331m_ = daq331m->daq331m_dll_.DAQ331M_New();
}

static void delete_device(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return;
    }
    daq331m->daq331m_dll_.DAQ331M_Delete(daq331m->daq331m_);
    daq331m->daq331m_ = NULL;
}

static bool initialize_device(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    else
    {
        return daq331m->daq331m_dll_.DAQ331M_InitializeDevice(daq331m->daq331m_);
    }
}

static bool connected_device(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConnectedDevice(daq331m->daq331m_);
}

static bool use_serial_backend(daq331m_ptr daq331m, const char *uart_name, uint32_t baud_rate)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_UseSerialBackend(daq331m->daq331m_, uart_name, baud_rate);
}

static bool use_tcp_client_backend(daq331m_ptr daq331m, const char *ip_address, int address)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_UseTCPClientBackend(daq331m->daq331m_, ip_address, address);
}

static bool use_modbus_backend(daq331m_ptr daq331m, const char *uart_name, int baud_rate, int address)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_UseModbusRTUBackend(daq331m->daq331m_, uart_name, baud_rate, address);
}

static bool configure_adc_parameters(daq331m_ptr daq331m, uint32_t sample_rate, uint32_t voltage)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConfigureADCParameters(daq331m->daq331m_, sample_rate, voltage);
}

static bool configure_adc_channel(daq331m_ptr daq331m, uint8_t channel_state)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConfigADCChannel(daq331m->daq331m_, channel_state);
}

static bool start_collection(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_StartCollection(daq331m->daq331m_);
}

static bool stop_collection(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_StopCollection(daq331m->daq331m_);
}

static bool try_read_adc_data(daq331m_ptr daq331m, uint8_t channel, double *read_buffer, uint32_t read_size,
                              uint32_t timeout)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_TryReadADCData(daq331m->daq331m_, channel, read_buffer, read_size, timeout);
}

static uint32_t get_adc_enable_channel_size(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return 0;
    }
    return daq331m->daq331m_dll_.DAQ331M_GetADCEnableChannelSize(daq331m->daq331m_);
}

static uint32_t get_current_sample_rate(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return 0;
    }
    return daq331m->daq331m_dll_.DAQ331M_GetCurrentSampleRate(daq331m->daq331m_);
}

static uint32_t get_adc_legal_channel_size(daq331m_ptr daq331m)
{
    if (daq331m->daq331m_ == NULL)
    {
        return 0;
    }
    return daq331m->daq331m_dll_.DAQ331M_GetADCLegalChannelSize(daq331m->daq331m_);
}

static bool adc_data_is_ready(daq331m_ptr daq331m, uint32_t data_num)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ADCDataIsReady(daq331m->daq331m_, data_num);
}

static bool config_dac_mode(daq331m_ptr daq331m, uint32_t channel, uint32_t mode)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConfigDACMode(daq331m->daq331m_, channel, mode);
}

static bool config_dac_direct_current_data(daq331m_ptr daq331m, uint32_t channel, double data)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConfigDACDirectCurrentData(daq331m->daq331m_, channel, data);
}

static bool config_dac_wave_data(daq331m_ptr daq331m, uint32_t channel, uint32_t frequency, double *data)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_ConfigDACWaveData(daq331m->daq331m_, channel, frequency, data);
}

static bool start_dac(daq331m_ptr daq331m, uint32_t channel)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_StartDAC(daq331m->daq331m_, channel);
}

static bool stop_dac(daq331m_ptr daq331m, uint32_t channel)
{
    if (daq331m->daq331m_ == NULL)
    {
        return false;
    }
    return daq331m->daq331m_dll_.DAQ331M_StopDAC(daq331m->daq331m_, channel);
}

bool daq331m_init(daq331m_ptr daq331m)
{
#if WIN32
    daq331m->daq331m_dll_.handle = LoadLibrary(LIBRARY_NAME);
    if (daq331m->daq331m_dll_.handle == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        return false;
    }
#elif __linux__
    char *error;
    daq331m->daq331m_dll_.handle = dlopen(LIBRARY_NAME, RTLD_LAZY);
    if (!daq331m->daq331m_dll_.handle)
    {
        fprintf(stderr, "%s\n", dlerror());
        exit(EXIT_FAILURE);
    }
#endif

#if __linux__
    dlerror();
#endif

    daq331m->daq331m_dll_.DAQ331M_New =
        (uint32_t *(*)(void))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_New");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_New == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_Delete =
        (void (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_Delete");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_Delete == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_InitializeDevice =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_InitializeDevice");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_InitializeDevice == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConnectedDevice =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_ConnectedDevice");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConnectedDevice == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_SwitchingCommunicationProtocols = (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(
        daq331m->daq331m_dll_.handle, "DAQ331M_SwitchingCommunicationProtocols");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_SwitchingCommunicationProtocols == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_UseSerialBackend =
        (uint32_t (*)(uint32_t *, const char *, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                            "DAQ331M_UseSerialBackend");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_UseSerialBackend == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_UseTCPClientBackend = (uint32_t (*)(uint32_t *, const char *, int))LOAD_LIBRARY_FUNC(
        daq331m->daq331m_dll_.handle, "DAQ331M_UseTCPClientBackend");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_UseTCPClientBackend == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_UseModbusRTUBackend =
        (uint32_t (*)(uint32_t *, const char *, int, int))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                            "DAQ331M_UseModbusRTUBackend");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_UseModbusRTUBackend == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConfigureADCParameters =
        (uint32_t (*)(uint32_t *, uint32_t, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                        "DAQ331M_ConfigureADCParameters");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConfigureADCParameters == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_StartCollection =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_StartCollection");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_StartCollection == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_StopCollection =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_StopCollection");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_StopCollection == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_TryReadADCData =
        (uint32_t (*)(uint32_t *, uint8_t, double *, uint32_t, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                                           "DAQ331M_TryReadADCData");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_TryReadADCData == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ADCDataIsReady =
        (uint32_t (*)(uint32_t *, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_ADCDataIsReady");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ADCDataIsReady == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConfigADCChannel =
        (uint32_t (*)(uint32_t *, uint8_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_ConfigADCChannel");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConfigADCChannel == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_GetADCLegalChannelSize =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_GetADCLegalChannelSize");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_GetADCLegalChannelSize == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_GetADCBufferDataSize =
        (uint32_t (*)(uint32_t *, int))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_GetADCBufferDataSize");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_GetADCBufferDataSize == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_GetADCEnableChannelSize =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_GetADCEnableChannelSize");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_GetADCEnableChannelSize == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_GetCurrentSampleRate =
        (uint32_t (*)(uint32_t *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_GetCurrentSampleRate");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_GetCurrentSampleRate == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConfigDACMode = (uint32_t (*)(uint32_t *, uint32_t, uint32_t))LOAD_LIBRARY_FUNC(
        daq331m->daq331m_dll_.handle, "DAQ331M_ConfigDACMode");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConfigDACMode == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConfigDACDirectCurrentData =
        (uint32_t (*)(uint32_t *, uint32_t, double))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                      "DAQ331M_ConfigDACDirectCurrentData");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConfigDACDirectCurrentData == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_ConfigDACWaveData =
        (uint32_t (*)(uint32_t *, uint32_t, uint32_t, double *))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle,
                                                                                  "DAQ331M_ConfigDACWaveData");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_ConfigDACWaveData == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_StartDAC =
        (uint32_t (*)(uint32_t *, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_StartDAC");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_StartDAC == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->daq331m_dll_.DAQ331M_StopDAC =
        (uint32_t (*)(uint32_t *, uint32_t))LOAD_LIBRARY_FUNC(daq331m->daq331m_dll_.handle, "DAQ331M_StopDAC");
#if WIN32
    if (daq331m->daq331m_dll_.DAQ331M_StopDAC == NULL)
    {
        fprintf(stderr, "Error: %ld\n", GetLastError());
        FreeLibrary(daq331m->daq331m_dll_.handle);
        return false;
    }
#elif __linux__
    if ((error = dlerror()) != NULL)
    {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }
#endif

    daq331m->create_device = create_device;
    daq331m->delete_device = delete_device;
    daq331m->initialize_device = initialize_device;
    daq331m->connected_device = connected_device;
    daq331m->use_serial_backend = use_serial_backend;
    daq331m->use_tcp_client_backend = use_tcp_client_backend;
    daq331m->use_modbus_backend = use_modbus_backend;
    daq331m->configure_adc_parameters = configure_adc_parameters;
    daq331m->configure_adc_channel = configure_adc_channel;
    daq331m->start_collection = start_collection;
    daq331m->stop_collection = stop_collection;
    daq331m->try_read_adc_data = try_read_adc_data;
    daq331m->get_adc_enable_channel_size = get_adc_enable_channel_size;
    daq331m->get_current_sample_rate = get_current_sample_rate;
    daq331m->get_adc_legal_channel_size = get_adc_legal_channel_size;
    daq331m->adc_data_is_ready = adc_data_is_ready;
    daq331m->config_dac_mode = config_dac_mode;
    daq331m->config_dac_direct_current_data = config_dac_direct_current_data;
    daq331m->config_dac_wave_data = config_dac_wave_data;
    daq331m->start_dac = start_dac;
    daq331m->stop_dac = stop_dac;

    return true;
}

bool daq331m_deinit(daq331m_ptr daq331m)
{
    if (daq331m != NULL)
    {
        daq331m->delete_device(daq331m);
        FREE_LIBRARY_FUNC(daq331m->daq331m_dll_.handle);
    }
    return true;
}
